package main

import "fmt"

// 1、 自定义类型
type myInt int
type myFn func(int, int) int

// 2、 类型别名
type myFloat = float64

// 3、结构体定义
/*
  注意：结构体首字母大写标识公有，小写表示私有
*/
type People struct {
	name   string
	age    int
	gender string
}

func main() {

	var a myInt = 10
	fmt.Printf("a的值：%v,类型：%T\n", a, a) //a的值：10,类型：main.myInt

	var b myFn = func(a, b int) int {
		return a + b
	}
	fmt.Printf("b的返回值：%v\n", b(1, 2))

	var c myFloat = 3.14
	fmt.Printf("c的值：%v,类型：%T\n", c, c) //c的值：3.14,类型：float64

	//实例化结构体
	var d People
	d.name = "ljl"
	d.age = 23
	d.gender = "男"
	fmt.Printf("d的值：%v,类型：%T\n", d, d)  //d的值：{ljl 23 男},类型：main.People
	fmt.Printf("d的值：%#v,类型：%T\n", d, d) //d的值：main.People{name:"ljl", age:23, gender:"男"},类型：main.People

	/*
	   注意：在golang中支持对结构体指针直接使用，来访问结构体的成员。e.name = "ljl2" 其实在底层是（*e）.name
	*/
	var e = new(People)
	e.name = "ljl2"
	e.age = 24
	(*e).name = "ljl3"
	e.gender = "男"
	fmt.Printf("e的值：%#v,类型：%T\n", e, e) //&main.People{name:"ljl3", age:24, gender:"男"},类型：*main.People

	var f = &People{}
	f.name = "ljl4"
	f.age = 25
	(*f).gender = "女"
	fmt.Printf("f的值：%#v,类型：%T\n", f, f) //&main.People{name:"ljl4", age:25, gender:"女"},类型：*main.People

	var g = People{
		name:   "ljl5",
		age:    26,
		gender: "不明",
	}
	fmt.Printf("g的值：%#v,类型：%T\n", g, g) //main.People{name:"ljl5", age:26, gender:"不明"},类型：main.People

	var h = &People{
		name:   "ljl6",
		age:    27,
		gender: "不明",
	}
	fmt.Printf("h的值：%#v,类型：%T\n", h, h) //&main.People{name:"ljl6", age:27, gender:"不明"},类型：*main.People

	var i = People{
		name: "ljl7", //不设置初始值  age 默认0 gender默认""
	}
	fmt.Printf("i的值：%#v,类型：%T\n", i, i) //main.People{name:"ljl7", age:0, gender:""},类型：main.People

	j := People{
		"ljl8",
		21,
		"男",
	}
	fmt.Printf("j的值：%#v,类型：%T\n", j, j) //main.People{name:"ljl8", age:21, gender:"男"},类型：main.People
}
